package com.chat.service;

import com.chat.Local;
import com.chat.common.Group;
import com.chat.common.Message;
import com.chat.common.MessageType;
import com.chat.view.GroupVerifyView;
import com.chat.view.VerifyMessageView;
import javafx.application.Platform;

import static com.chat.view.GroupVerifyController.groupver;
import static com.chat.view.VerifyMessageController.ver;

import java.awt.*;
import java.util.Objects;

/*
   添加群成员
 */
public class AddGroupMember {
       public void addgroupmember(String groupid,String memberid,String state){//群id,成员id，成员地位
              Message msg=new Message();
              Group group=new Group();
              group.setId(groupid);
              group.setMemberid(memberid);
              group.setMemberstate(state);
              msg.setMesType(MessageType.MESSAGE_ADD_GROUP_MEMBER);
              msg.setData(group);
              ClientConnectServerThread clientConnectServerThread=ManageClientConnectServerThread.getClientConnectServerThread(Local.user.getUsername());
              clientConnectServerThread.send(msg);
              if(!Objects.equals(state, "3")) {
                     Platform.runLater(new Runnable() {
                            @Override
                            public void run() {
                                   ((javafx.scene.control.ListView) GroupVerifyView.$("verify")).getItems().clear();
                            }
                     });
                     groupver.clear();
                     GetGroupVerify ggv = new GetGroupVerify();
                     ggv.getgroupverify();
              }
       }
       public void add(String groupid,String memberid,String state) {//群id,成员id，成员地位
              Message msg=new Message();
              Group group=new Group();
              group.setId(groupid);
              group.setMemberid(memberid);
              group.setMemberstate(state);
              msg.setMesType(MessageType.MESSAGE_ADD_GROUP_MEMBER);
              msg.setData(group);
              ClientConnectServerThread clientConnectServerThread=ManageClientConnectServerThread.getClientConnectServerThread(Local.user.getUsername());
              clientConnectServerThread.send(msg);
       }
}
